home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / MOVE.ASM < prev    next >
Assembly Source File  |  1986-02-05  |  9KB  |  150 lines

  1. CODE_SEG        SEGMENT
  2.         ORG     100H                    ;ORG 100H for a .com file
  3.         ASSUME  CS:CODE_SEG,DS:CODE_SEG
  4. FIRST:  JMP     ENTRY                   ;Skip over data area
  5.         COPYRIGHT       DB      '(C) S. HOLZNER 1984'
  6.         TARGET_FCB      DB      37 DUP(0) ;FCB at 6CH will be written over
  7.         END_FLAG        DW      0               ;Flag set after everything read
  8.         FILE_SIZE_LO    DW      0               ;Low word of file size, in bytes
  9.         FILE_SIZE_HI    DW      0               ;High word of same
  10.         FILE_SIZE_K     DW      0               ;Number of Clusters to write
  11.         DTA_OFFSET      DW      0               ;Used for 1K increments into DTA
  12.         COPY_MSG_1      DB      13,10,'Copy $'  ;Part 1 of the copy prompt
  13.         COPY_MSG_2      DB      ' (Y/N)?$'      ;And part 2
  14.         FULL_MSG        DB      13,10,'Disk Full$'      ;Trouble message
  15.  
  16. MOVE    PROC    NEAR                    ;The main (and only) procedure
  17. ENTRY:  MOV     CX,32                   ;Copy over 1st 32 bytes of default DTA
  18.         MOV     SI,6CH                  ; from 6CH into Target_FCB area for 
  19.         LEA     DI,TARGET_FCB           ; later use as new file name
  20. REP     MOVSB
  21.         MOV     DX,5CH                  ;The source FCB
  22.         MOV     AH,11H                  ;Check if there is match to source file
  23.         INT     21H
  24.         CMP     AL,0FFH                 ;0FFH -> No match
  25.         JNE     QUERY                   ;Match
  26.         JMP     OUT                     ;No Match
  27. QUERY:  MOV     AH,9H                   ;Print out prompt message
  28.         LEA     DX,COPY_MSG_1
  29.         INT     21H
  30.         MOV     CX,11                   ;Print out 11 letters of found file name
  31.         MOV     BX,81H                  ;Point to match in default DTA
  32.         MOV     AH,2
  33. QLOOP:  MOV     DL,[BX]                 ;Get letter of found file's name
  34.         INC     BX                      ;Point to next letter
  35.         INT     21H
  36.         LOOP    QLOOP                   ;Keep going until all 11 printed
  37.         MOV     AH,9H                   ;Print out 2nd half of prompt message
  38.         LEA     DX,COPY_MSG_2
  39.         INT     21H
  40.         MOV     AH,1                    ;Get a 1 character response
  41.         INT     21H
  42.         CMP     AL,'Y'                  ;Was it a 'Y'?
  43.         JE      DO_COPY                 ;Yes, copy the file
  44.         CMP     AL,'y'                  ;No...perhaps a 'y'?
  45.         JE      DO_COPY                 ;Yes, copy the file
  46.         JMP     NEXT                    ;Get next match (if none, leave)
  47. DO_COPY:MOV     CX,37                   ;Using given target file as a template,
  48.         LEA     SI,TARGET_FCB           ; load its 37 characters into the FCB
  49.         MOV     DI,0C0H                 ; for use as real target FCB, checking
  50.         CMP     BYTE PTR [SI+1],' '     ; for wildcards. First, was DRIVE: given
  51.         JNE     NLOOP                   ; as target? No, check wildcards.
  52.         PUSH    DI                      ;Yes, fill Target_FCB with wildcard ?'s 
  53.         PUSH    CX                      ; so found filename will be used
  54.         LEA     DI,TARGET_FCB
  55.         INC     DI
  56.         MOV     CX,11                   ;Put in 11 ?'s
  57.         MOV     AL,'?'
  58. REP     STOSB                           ;Do the fill
  59.         POP     CX                      ;Restore counter and dest. pointer
  60.         POP     DI
  61. NLOOP:  MOV     BX,0                    ;Move given target name into real used
  62.         CMP     BYTE PTR [SI],'?'       ; target FCB at 0C0H. If a wildcard is 
  63.         JNE     CHAR_OK                 ; found in given filename use corres-
  64.         MOV     BX,80H                  ; ponding character in found filename
  65.         SUB     BX,OFFSET TARGET_FCB    ;Wildcard found, adjust source (SI) to
  66.         ADD     SI,BX                   ; point to the found filename
  67. CHAR_OK:MOVS    [DI],[SI]
  68.         SUB     SI,BX                   ;Restore SI if necessary
  69.         LOOP    NLOOP                   ;Loop back until for all 11 name char.s
  70.         MOV     DX,80H                  ;Target FCB now at 0C0H, source at 80H
  71.         MOV     AH,0FH                  ;Use DOS service 15 to open source
  72.         INT     21H                     ;Open source FCB
  73.         MOV     DX,0C0H                 ;Use DOS service 12 to create target
  74.         MOV     AH,16H
  75.         INT     21H                     ;Create target FCB (or if the file 
  76.         AND     END_FLAG,0              ; already exists, zero it and refill it)
  77.         MOV     BX,80H + 14
  78.         MOV     WORD PTR [BX],8000H     ;Set record size for source (32K)
  79.         MOV     BX,80H + 16             ;Get file size from opened source FCB
  80.         MOV     AX,[BX]
  81.         MOV     FILE_SIZE_LO,AX         ;Store low word of size in FILE_SIZE_LO
  82.         ADD     BX,2                    ;Point to high word
  83.         MOV     DX,[BX]
  84.         MOV     FILE_SIZE_HI,DX         ;Store high word of size in FILE_SIZE_HI
  85.         MOV     CX,1024                 ;Div DX:AX (High:Low of size) by 1024
  86.         DIV     CX
  87.         MOV     FILE_SIZE_K,AX          ;Get file size in rounded-up K (1024)
  88.         TEST    DX,0FFFFH               ;Was it an even K file:Mod(size,1024)=0?
  89.         JZ      ROUND                   ;Yes, don't add cluster for file remnant
  90.         INC     FILE_SIZE_K             ;No, add 1 more cluster for remainder
  91. ROUND:  MOV     BX,0C0H + 14
  92.         MOV     WORD PTR [BX],400H      ;Set record size for target (1K)
  93. READ:   LEA     DX,DATA_POINT           ;Set up the 32K DTA we'll use
  94.         MOV     AH,1AH                  ; at the end of this program
  95.         INT     21H                     
  96.         MOV     DX,80H                  ;Point to source FCB to prepare for read
  97.         MOV     AH,14H
  98.         INT     21H                     ;Do the read of 32K bytes
  99.         CMP     AL,0                    ;AL = 0 if end of file not yet reached
  100.         JLE     READ_OK
  101.         OR      END_FLAG,1              ;Have read in the whole file, DTA is
  102. READ_OK:MOV     CX,20H                  ; stuffed with zeroes after end of file
  103.         LEA     DX,DATA_POINT           ;Reset our offset into 32K DTA to the
  104.         MOV     DTA_OFFSET,DX           ; start
  105. WLOOP:  MOV     DX,0C0H                 ;Point to target FCB, prepare for write
  106.         MOV     AH,15H
  107.         INT     21H                     ;Do the write 1K at a time
  108.         CMP     AL,0                    ;Was the write a success?
  109.         JE      COPY_OK                 ;Yes, check if done writing
  110.         LEA     DX,FULL_MSG             ;No, assume the disk was full and say so
  111.         MOV     AH,9H                   ;Print error string
  112.         INT     21H
  113.         JMP     OUT                     ;Exit 
  114. COPY_OK:DEC     FILE_SIZE_K             ;Decrement number of clusters to write
  115.         JZ      FINISH                  ;Done?
  116.         ADD     DTA_OFFSET,400H         ;No, point to next 1K chunk of DTA
  117.         MOV     DX,DTA_OFFSET           
  118.         MOV     AH,1AH                  ;Set DTA to match
  119.         INT     21H
  120.         LOOP    WLOOP                   ;Repeat until 32K written or end of file
  121.         TEST    END_FLAG,1              ;Have we read in the end of file?
  122.         JZ      READ                    ;No, get next 32K block from source
  123. FINISH: MOV     AX,FILE_SIZE_LO         ;Now adjust written file's size
  124.         MOV     BX,0C0H + 16            ;Point to low word of size
  125.         MOV     WORD PTR [BX],AX        ;And set it to the correct value
  126.         ADD     BX,2                    ;Point to high word of size
  127.         MOV     AX,FILE_SIZE_HI         ;And set it too
  128.         MOV     WORD PTR [BX],AX
  129.         MOV     AH,10H                  ;Request DOS service 16, close files
  130.         MOV     DX,0C0H                 ;Point to target file's FCB
  131.         INT     21H                     ;Close target with correct size
  132.         MOV     DX,80H                  ;Point to source file's FCB
  133.         INT     21H                     ;Close source
  134. NEXT:   MOV     DX,80H                  ;Start looking for the next match
  135.         MOV     AH,1AH          ;First, reset DTA to 80H for found file's FCB
  136.         INT     21H             
  137.         MOV     AH,12H                  ;Now search for next match-service 18
  138.         MOV     DX,5CH                  ;Use given filename to match to
  139.         INT     21H
  140.         CMP     AL,0                    ;Match found?
  141.         JNE     OUT                     ;No, exit.
  142.         JMP     QUERY                   ;Yes, ask if it should be copied
  143. OUT:    RET
  144.  
  145. MOVE    ENDP
  146. DATA_POINT:                             ;The 32K DTA starts here
  147. CODE_SEG        ENDS
  148.         END     FIRST                   ;'END FIRST' so entry point set to FIRST
  149.  
  150.